home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / SearchResults.aspx.cs612 < prev    next >
Text File  |  2008-05-25  |  46KB  |  860 lines

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. using System.Data.Common;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using System.Web.UI.WebControls;
  8. using System.Web;
  9. using System.Xml;
  10. using GBPVR.Public;
  11. using GBPVRSchedule;
  12. using gbweb.classes;
  13.  
  14. namespace gbweb
  15. {
  16.     /// <summary>
  17.     /// Summary description for SearchResults.
  18.     /// </summary>
  19.     public partial class SearchResults : System.Web.UI.Page
  20.     {
  21.         protected System.Web.UI.WebControls.DropDownList DropDownList1;
  22.         protected Settings guideParams;
  23.         protected ProgramTreeItem[] pgmTree;
  24.         protected int treeIdx;
  25.  
  26.         private string sortOrder = string.Empty;
  27.         private ArrayList sortOrders;
  28.         private ArrayList displayProgrammeSort = new ArrayList();
  29.  
  30.         Hashtable channelCache = new Hashtable();
  31.  
  32.         protected void Page_Load(object sender, System.EventArgs e)
  33.         {
  34.             treeIdx = 0;
  35.             pgmTree = new ProgramTreeItem[10000];
  36.             guideParams = Global.Settings;
  37.             HttpCookie cookie = Request.Cookies["showSearchResults"];
  38.  
  39.             if (!IsPostBack)
  40.             {
  41.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  42.                 //options otherwise do not show them
  43.  
  44.                 XmlNode pre = Global.Config.SelectSingleNode("/settings/PreShowPadding");
  45.                 XmlNode post = Global.Config.SelectSingleNode("/settings/PostShowPadding");
  46.                 prePadding.Text = pre.InnerText;
  47.                 postPadding.Text = post.InnerText;
  48.  
  49.                 sr_searchResults.SelectedValue = cookie != null ? cookie.Value : "tree";
  50.  
  51.                 if (sr_searchResults.SelectedValue == "tree")
  52.                 {
  53.                     treeView.Visible = true;
  54.                     footer.Visible = false;
  55.                     treeViewSortOptions.Visible = true;
  56.                     tableView.Visible = false;
  57.                     
  58.                     //If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
  59.                     if (ExtendedEWA.Initialize())
  60.                     {
  61.                         ListItem starRating = new ListItem();
  62.                         starRating.Text = "Star Rating";
  63.                         starRating.Value = "star";
  64.                         srtOrder.Items.Add(starRating);
  65.  
  66.                         ListItem originalAirDate = new ListItem();
  67.                         originalAirDate.Text = "Original Air Date (oad)";
  68.                         originalAirDate.Value = "originalAirDate";
  69.                         srtOrder.Items.Add(originalAirDate);
  70.                     }
  71.  
  72.                     //Set the selected search order to whatever was used on the search criteria page
  73.                     string treeSortOrder = Convert.ToString(Session["SearchResultsOption"]);
  74.                     if (treeSortOrder != null)
  75.                     {
  76.                         srtOrder.SelectedValue = sortOrder;
  77.                     }
  78.                     else
  79.                     {
  80.                         cookie = Request.Cookies["SearchSortOrder"];
  81.                         srtOrder.SelectedValue = cookie != null ? cookie.Value : "title";
  82.                     }
  83.                     //Store the selected display (table or tree) in the cookie for the next search
  84.                     cookie = new HttpCookie("showSearchResults", sr_searchResults.SelectedValue);
  85.                     cookie.Expires = DateTime.Now.AddYears(1);
  86.                     Response.Cookies.Add(cookie);
  87.                 }
  88.                 else
  89.                 {
  90.                     treeView.Visible = false;
  91.                     footer.Visible = true;
  92.                     treeViewSortOptions.Visible = false;
  93.                     tableView.Visible = true;
  94.                 }
  95.  
  96.                 if ((Request.Params["checkTitle"] != null) || (Request.Params["checkDescription"] != null) || (Request.Params["checkSubtitle"] != null) || (Request.Params["listChannels"] != null) ||
  97.                     (Request.Params["matchTitle"] != null) || (Request.Params["matchDesc"] != null) || (Request.Params["matchSubtitle"] != null) || (Request.Params["matchUniqueID"] != null) ||
  98.                     (Request.Params["textMinLength"] != null) && (Request.Params["textMinLength"].Length > 0) ||
  99.                     ((Request.Params["textMaxLength"] != null) && (Request.Params["textMaxLength"].Length > 0)) ||
  100.                     Request.Params["startDate"] != null || Request.Params["startTime"] != null ||
  101.                     Request.Params["endDate"] != null || Request.Params["endTime"] != null)
  102.                 {
  103.                     int minLength = int.MinValue;
  104.                     int maxLength = int.MaxValue;
  105.                     Session["startDate"] = "01/01/1901";
  106.                     Session["startTime"] = "01:01 AM";
  107.                     Session["endDate"] = "01/01/1901";
  108.                     Session["endTime"] = "01:01 AM";
  109.  
  110.                     if ((Request.Params["textMinLength"] != null) && (Request.Params["textMinLength"].Length > 0)) minLength = int.Parse(Request.Params["textMinLength"]);
  111.                     if ((Request.Params["textMaxLength"] != null) && (Request.Params["textMaxLength"].Length > 0)) maxLength = int.Parse(Request.Params["textMaxLength"]);
  112.  
  113.                     if ((Request.Params["startDate:textBox"] != null) && (Request.Params["startDate:textBox"].Length > 0))
  114.                     {
  115.                         Session["startDate"] = Request.Params["startDate:textBox"];
  116.                     }
  117.  
  118.                     if ((Request.Params["startTime:textBox"] != null) && (Request.Params["startTime:textBox"].Length > 0))
  119.                     {
  120.                         Session["startTime"] = Request.Params["startTime:textBox"];
  121.                     }
  122.  
  123.                     if ((Request.Params["endDate:textBox"] != null) && (Request.Params["endDate:textBox"].Length > 0))
  124.                     {
  125.                         Session["endDate"] = Request.Params["endDate:textBox"];
  126.                     }
  127.  
  128.                     if ((Request.Params["endTime:textBox"] != null) && (Request.Params["endTime:textBox"].Length > 0))
  129.                     {
  130.                         Session["endTime"] = Request.Params["endTime:textBox"];
  131.                     }
  132.  
  133.                     string[] channels = new string[0] { };
  134.                     if (Request.Params["listChannels"] != null) channels = Request.Params["listChannels"].Split(',');
  135.  
  136.                     string[] genres = new string[0] { };
  137.                     if (Request.Params["genreList"] != null) genres = Request.Params["genreList"].Split(',');
  138.  
  139.                     Session["checkTitle"] = Request.Params["checkTitle"] != null;
  140.                     Session["checkDescription"] = Request.Params["checkDescription"] != null;
  141.                     Session["checkSubtitle"] = Request.Params["checkSubtitle"] != null;
  142.                     Session["matchTitle"] = Request.Params["matchTitle"] != null;
  143.                     Session["matchDesc"] = Request.Params["matchDesc"] != null;
  144.                     Session["matchSubtitle"] = Request.Params["matchSubtitle"] != null;
  145.                     Session["matchUniqueID"] = Request.Params["matchUniqueID"] != null;
  146.                     Session["textKeyWord"] = Request.Params["searchPhrase"];
  147.                     Session["caseSensitive"] = Request.Params["caseSensitive"] != null;
  148.                     Session["genreList"] = genres;
  149.                     Session["minLength"] = minLength;
  150.                     Session["maxLength"] = maxLength;
  151.                     Session["channels"] = channels;
  152.  
  153.                     //Set the default recording Quality
  154.                     quality.SelectedValue = Global.Settings.recordingQuality;
  155.                 }
  156.                 else
  157.                 {
  158.                     if (Request["sort"] == null)
  159.                     {
  160.                         Response.Redirect("Search.aspx");
  161.                     }
  162.                 }
  163.             }
  164.             else
  165.             {
  166.                 if (sr_searchResults.SelectedValue == "tree")
  167.                 {
  168.                     //Store the selected sort order in the cookie for the next search
  169.                     cookie = new HttpCookie("SearchSortOrder", srtOrder.SelectedValue);
  170.                     cookie.Expires = DateTime.Now.AddYears(1);
  171.                     Response.Cookies.Add(cookie);
  172.                     
  173.                     treeView.Visible = true;
  174.                     footer.Visible = false;
  175.                     treeViewSortOptions.Visible = true;
  176.                     tableView.Visible = false;
  177.                 }
  178.                 else
  179.                 {
  180.                     treeView.Visible = false;
  181.                     footer.Visible = true;
  182.                     treeViewSortOptions.Visible = false;
  183.                     tableView.Visible = true;
  184.                 }
  185.             }
  186.             
  187.             //Store the selected display (table or tree) in the cookie for the next search
  188.             cookie = new HttpCookie("showSearchResults", sr_searchResults.SelectedValue);
  189.             cookie.Expires = DateTime.Now.AddYears(1);
  190.             Response.Cookies.Add(cookie);
  191.  
  192.             //Read the cookie for the sort order of the display
  193.             cookie = Request.Cookies["sortOrderSearch"];
  194.             sortOrder = cookie != null ? cookie.Value.Trim(',') : "channel,datetime,title";
  195.             //cookie.Value = "channel,datetime,title,status";
  196.             //sortOrder = "channel,datetime,title,status";
  197.             sortOrders = new ArrayList(sortOrder.Split(','));
  198.             string newSort = Request["sort"];
  199.             if (newSort != null)
  200.             {
  201.                 if (sortOrders.Contains(newSort))
  202.                 {
  203.                     if (sortOrders[0].ToString() == newSort)
  204.                     {
  205.                         sortOrders.Remove(newSort);
  206.                         sortOrders.Insert(0, newSort + " desc");
  207.                     }
  208.                     else
  209.                     {
  210.                         sortOrders.Remove(newSort);
  211.                         sortOrders.Insert(0, newSort);
  212.                     }
  213.                 }
  214.                 else
  215.                 {
  216.                     sortOrders.Remove(newSort + " desc");
  217.                     sortOrders.Insert(0, newSort);
  218.                 }
  219.             }
  220.             sortOrder = string.Join(",", (string[])sortOrders.ToArray(typeof(string)));
  221.  
  222.             //Update the sort settings in the cookie for the next display
  223.             cookie = new HttpCookie("sortOrderSearch", sortOrder);
  224.             cookie.Expires = DateTime.Now.AddYears(1);
  225.             Response.Cookies.Add(cookie);
  226.         }
  227.  
  228.         protected void SearchResults_PreRender(object sender, System.EventArgs e)
  229.         {
  230.             SearchForEpisode(
  231.                 (bool)Session["checkTitle"],
  232.                 (bool)Session["checkDescription"],
  233.                 (bool)Session["checkSubtitle"],
  234.                 (bool)Session["matchTitle"],
  235.                 (bool)Session["matchDesc"],
  236.                 (bool)Session["matchSubtitle"],
  237.                 (bool)Session["matchUniqueID"],
  238.                 (string)Session["textKeyWord"],
  239.                 (bool)Session["caseSensitive"],
  240.                 (int)Session["minLength"],
  241.                 (int)Session["maxLength"],
  242.                 (string[])Session["channels"],
  243.                 (string[])Session["genreList"],
  244.                 (string)Session["startDate"],
  245.                 (string)Session["startTime"],
  246.                 (string)Session["endDate"],
  247.                 (string)Session["endTime"]);
  248.         }
  249.  
  250.         protected void hlRecord_Click(object sender, System.EventArgs e)
  251.         {
  252.             // schedule recordings
  253.             Schedule.Quality quality = 0;
  254.             switch (Request.Params["quality"].ToLower())
  255.             {
  256.                 case "high":
  257.                     quality = Schedule.Quality.High;
  258.                     break;
  259.  
  260.                 case "medium":
  261.                     quality = Schedule.Quality.Medium;
  262.                     break;
  263.  
  264.                 case "low":
  265.                     quality = Schedule.Quality.Low;
  266.                     break;
  267.  
  268.                 case "custom1":
  269.                     quality = Schedule.Quality.Custom1;
  270.                     break;
  271.  
  272.                 case "custom2":
  273.                     quality = Schedule.Quality.Custom2;
  274.                     break;
  275.             }
  276.  
  277.             Schedule scheduleHelper = Global.Schedule;
  278.             int prePad = Convert.ToInt32(prePadding.Text);
  279.             int postPad = Convert.ToInt32(postPadding.Text);
  280.             if (radioTime.SelectedValue == "once")
  281.             {
  282.                 if (sr_searchResults.SelectedValue != "tree")
  283.                 {
  284.                     foreach (string param in Request.Params.Keys)
  285.                     {
  286.                         if (param.StartsWith("item"))
  287.                         {
  288.                             Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(param.Substring(4)));
  289.                             
  290.                             Schedule myschedule = Global.Schedule;
  291.  
  292.                             if (Convert.ToDouble(extendMinutes.Text) != 0)
  293.                             {
  294.                                 //Add the number of minutes that was entered to the end time of the recording to set the new end time
  295.                                 DateTime newEndDate =
  296.                                     programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  297.                                 //Set the new end time for the recording
  298.                                 programme.setEndTime(newEndDate);
  299.                             }
  300.  
  301.                             bool scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  302.                             Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  303.                             Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  304.                         }
  305.                     }
  306.                 }
  307.                 else
  308.                 {
  309.                     foreach (TreeNode node in TreeView1.CheckedNodes)
  310.                     {
  311.                         Programme programme = scheduleHelper.GetProgrammeByOID(System.Convert.ToInt32(node.Value));
  312.                         Schedule myschedule = Global.Schedule;
  313.  
  314.                         if (Convert.ToDouble(extendMinutes.Text) != 0)
  315.                         {
  316.                             //Add the number of minutes that was entered to the end time of the recording to set the new end time
  317.                             DateTime newEndDate =
  318.                                 programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  319.                             //Set the new end time for the recording
  320.                             programme.setEndTime(newEndDate);
  321.                         }
  322.  
  323.                         bool scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  324.                         Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  325.                         Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  326.                     }
  327.                 }
  328.             }
  329.             else
  330.             {
  331.                 HybridDictionary processedRecordings = new HybridDictionary();
  332.                 if (sr_searchResults.SelectedValue != "tree")
  333.                 {
  334.                     foreach (string param in Request.Params.Keys)
  335.                     {
  336.                         if (param.StartsWith("item"))
  337.                         {
  338.                             Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(param.Substring(4)));
  339.  
  340.                             if (Convert.ToDouble(extendMinutes.Text) != 0)
  341.                             {
  342.                                 //Add the number of minutes that was entered to the end time of the recording to set the new end time
  343.                                 DateTime newEndDate =
  344.                                     programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  345.                                 //Set the new end time for the recording
  346.                                 programme.setEndTime(newEndDate);
  347.                             }
  348.  
  349.                             string uniqueProgrammeKey = programme.getChannelOID().ToString() + ":" + programme.getTitle();
  350.  
  351.                             if (!processedRecordings.Contains(uniqueProgrammeKey))
  352.                             {
  353.                                 //Set the max number of recordings to keep for the show
  354.                                 int keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  355.                                 if (keepRecordings.Text.ToString() != null)
  356.                                 {
  357.                                     try
  358.                                     {
  359.                                         keepnumRecordings = Convert.ToInt32(keepRecordings.Text);
  360.                                     }
  361.                                     catch
  362.                                     {
  363.                                         keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  364.                                     }
  365.                                 }
  366.                                 else
  367.                                 {
  368.                                     keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  369.                                 }
  370.  
  371.                                 Schedule myschedule = Global.Schedule;
  372.  
  373.                                 if (radioTime.SelectedValue == "thisTime")
  374.                                 {
  375.                                     // schedule season recording for any day and this time
  376.                                     if (radioDay.SelectedValue == "anyDay")
  377.                                     {
  378.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  379.                                     }
  380.                                     // schedule season recording for only this day and this time
  381.                                     else if (radioDay.SelectedValue == "thisDay")
  382.                                     {
  383.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  384.                                     }
  385.                                     // schedule season recording for the selected days and this time
  386.                                     else
  387.                                     {
  388.                                         ArrayList dayList = new ArrayList();
  389.                                         // Iterate through the Items collection of the checkedDays 
  390.                                         // control and create the correct number for the season recording.
  391.                                         for (int i = 0; i < checkedDays.Items.Count; i++)
  392.                                         {
  393.                                             if (checkedDays.Items[i].Selected)
  394.                                             {
  395.                                                 switch (checkedDays.Items[i].Text)
  396.                                                 {
  397.                                                     case "Monday":
  398.                                                         dayList.Add(Schedule.Day.Monday);
  399.                                                         break;
  400.                                                     case "Tuesday":
  401.                                                         dayList.Add(Schedule.Day.Tuesday);
  402.                                                         break;
  403.                                                     case "Wednesday":
  404.                                                         dayList.Add(Schedule.Day.Wednesday);
  405.                                                         break;
  406.                                                     case "Thursday":
  407.                                                         dayList.Add(Schedule.Day.Thursday);
  408.                                                         break;
  409.                                                     case "Friday":
  410.                                                         dayList.Add(Schedule.Day.Friday);
  411.                                                         break;
  412.                                                     case "Saturday":
  413.                                                         dayList.Add(Schedule.Day.Saturday);
  414.                                                         break;
  415.                                                     case "Sunday":
  416.                                                         dayList.Add(Schedule.Day.Sunday);
  417.                                                         break;
  418.                                                 }
  419.                                             }
  420.                                         }
  421.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  422.                                     }
  423.                                 }
  424.                                 else
  425.                                 {
  426.                                     // schedule season recording for anyday anytime
  427.                                     if (radioDay.SelectedValue == "anyDay")
  428.                                     {
  429.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  430.                                     }
  431.                                     // schedule season recording for only this day and thisany time
  432.                                     else if (radioDay.SelectedValue == "thisDay")
  433.                                     {
  434.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  435.                                     }
  436.                                     // schedule season recording for the selected days and this time
  437.                                     else
  438.                                     {
  439.                                         ArrayList dayList = new ArrayList();
  440.                                         // Iterate through the Items collection of the checkedDays 
  441.                                         // control and create the correct number for the season recording.
  442.                                         for (int i = 0; i < checkedDays.Items.Count; i++)
  443.                                         {
  444.                                             if (checkedDays.Items[i].Selected)
  445.                                             {
  446.                                                 switch (checkedDays.Items[i].Text)
  447.                                                 {
  448.                                                     case "Monday":
  449.                                                         dayList.Add(Schedule.Day.Monday);
  450.                                                         break;
  451.                                                     case "Tuesday":
  452.                                                         dayList.Add(Schedule.Day.Tuesday);
  453.                                                         break;
  454.                                                     case "Wednesday":
  455.                                                         dayList.Add(Schedule.Day.Wednesday);
  456.                                                         break;
  457.                                                     case "Thursday":
  458.                                                         dayList.Add(Schedule.Day.Thursday);
  459.                                                         break;
  460.                                                     case "Friday":
  461.                                                         dayList.Add(Schedule.Day.Friday);
  462.                                                         break;
  463.                                                     case "Saturday":
  464.                                                         dayList.Add(Schedule.Day.Saturday);
  465.                                                         break;
  466.                                                     case "Sunday":
  467.                                                         dayList.Add(Schedule.Day.Sunday);
  468.                                                         break;
  469.                                                 }
  470.                                             }
  471.                                         }
  472.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  473.                                     }
  474.                                 }
  475.  
  476.                                 // drop out after first season recording for the show
  477.                                 // (it really doesn't matter what we store here, but myRecording sounds usefull)
  478.                                 processedRecordings.Add(uniqueProgrammeKey, programme);
  479.                                 Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  480.                                 Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  481.                             }
  482.                         }
  483.                     }
  484.                 }
  485.                 else
  486.                 {
  487.                     foreach (TreeNode node in TreeView1.CheckedNodes)
  488.                     {
  489.                         Programme programme = scheduleHelper.GetProgrammeByOID(System.Convert.ToInt32(node.Value));
  490.  
  491.                         if (Convert.ToDouble(extendMinutes.Text) != 0)
  492.                         {
  493.                             //Add the number of minutes that was entered to the end time of the recording to set the new end time
  494.                             DateTime newEndDate =
  495.                                 programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  496.                             //Set the new end time for the recording
  497.                             programme.setEndTime(newEndDate);
  498.                         }
  499.  
  500.                         string uniqueProgrammeKey = programme.getChannelOID().ToString() + ":" + programme.getTitle();
  501.  
  502.                         if (!processedRecordings.Contains(uniqueProgrammeKey))
  503.                         {
  504.                             //Set the max number of recordings to keep for the show
  505.                             int keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  506.                             if (keepRecordings.Text.ToString() != null)
  507.                             {
  508.                                 try
  509.                                 {
  510.                                     keepnumRecordings = Convert.ToInt32(keepRecordings.Text);
  511.                                 }
  512.                                 catch
  513.                                 {
  514.                                     keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  515.                                 }
  516.                             }
  517.                             else
  518.                             {
  519.                                 keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  520.                             }
  521.  
  522.                             Schedule myschedule = Global.Schedule;
  523.  
  524.                             if (radioTime.SelectedValue == "thisTime")
  525.                             {
  526.                                 // schedule season recording for any day and this time
  527.                                 if (radioDay.SelectedValue == "anyDay")
  528.                                 {
  529.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  530.                                 }
  531.                                 // schedule season recording for only this day and this time
  532.                                 else if (radioDay.SelectedValue == "thisDay")
  533.                                 {
  534.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  535.                                 }
  536.                                 // schedule season recording for the selected days and this time
  537.                                 else
  538.                                 {
  539.                                     ArrayList dayList = new ArrayList();
  540.                                     // Iterate through the Items collection of the checkedDays 
  541.                                     // control and create the correct number for the season recording.
  542.                                     for (int i = 0; i < checkedDays.Items.Count; i++)
  543.                                     {
  544.                                         if (checkedDays.Items[i].Selected)
  545.                                         {
  546.                                             switch (checkedDays.Items[i].Text)
  547.                                             {
  548.                                                 case "Monday":
  549.                                                     dayList.Add(Schedule.Day.Monday);
  550.                                                     break;
  551.                                                 case "Tuesday":
  552.                                                     dayList.Add(Schedule.Day.Tuesday);
  553.                                                     break;
  554.                                                 case "Wednesday":
  555.                                                     dayList.Add(Schedule.Day.Wednesday);
  556.                                                     break;
  557.                                                 case "Thursday":
  558.                                                     dayList.Add(Schedule.Day.Thursday);
  559.                                                     break;
  560.                                                 case "Friday":
  561.                                                     dayList.Add(Schedule.Day.Friday);
  562.                                                     break;
  563.                                                 case "Saturday":
  564.                                                     dayList.Add(Schedule.Day.Saturday);
  565.                                                     break;
  566.                                                 case "Sunday":
  567.                                                     dayList.Add(Schedule.Day.Sunday);
  568.                                                     break;
  569.                                             }
  570.                                         }
  571.                                     }
  572.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  573.                                 }
  574.                             }
  575.                             else
  576.                             {
  577.                                 // schedule season recording for anyday anytime
  578.                                 if (radioDay.SelectedValue == "anyDay")
  579.                                 {
  580.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  581.                                 }
  582.                                 // schedule season recording for only this day and thisany time
  583.                                 else if (radioDay.SelectedValue == "thisDay")
  584.                                 {
  585.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  586.                                 }
  587.                                 // schedule season recording for the selected days and this time
  588.                                 else
  589.                                 {
  590.                                     ArrayList dayList = new ArrayList();
  591.                                     // Iterate through the Items collection of the checkedDays 
  592.                                     // control and create the correct number for the season recording.
  593.                                     for (int i = 0; i < checkedDays.Items.Count; i++)
  594.                                     {
  595.                                         if (checkedDays.Items[i].Selected)
  596.                                         {
  597.                                             switch (checkedDays.Items[i].Text)
  598.                                             {
  599.                                                 case "Monday":
  600.                                                     dayList.Add(Schedule.Day.Monday);
  601.                                                     break;
  602.                                                 case "Tuesday":
  603.                                                     dayList.Add(Schedule.Day.Tuesday);
  604.                                                     break;
  605.                                                 case "Wednesday":
  606.                                                     dayList.Add(Schedule.Day.Wednesday);
  607.                                                     break;
  608.                                                 case "Thursday":
  609.                                                     dayList.Add(Schedule.Day.Thursday);
  610.                                                     break;
  611.                                                 case "Friday":
  612.                                                     dayList.Add(Schedule.Day.Friday);
  613.                                                     break;
  614.                                                 case "Saturday":
  615.                                                     dayList.Add(Schedule.Day.Saturday);
  616.                                                     break;
  617.                                                 case "Sunday":
  618.                                                     dayList.Add(Schedule.Day.Sunday);
  619.                                                     break;
  620.                                             }
  621.                                         }
  622.                                     }
  623.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  624.                                 }
  625.                             }
  626.  
  627.                             // drop out after first season recording for the show
  628.                             // (it really doesn't matter what we store here, but myRecording sounds usefull)
  629.                             processedRecordings.Add(uniqueProgrammeKey, programme);
  630.                             Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  631.                             Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  632.                         }
  633.                     }
  634.                 }
  635.             }
  636.         }
  637.  
  638.         private void SearchForEpisode(
  639.             bool checkTitle, bool checkDesc, bool checkSubtitle,
  640.             bool matchTitle, bool matchDesc, bool matchSubtitle, bool matchUniqueID,
  641.             String searchFor, bool caseSensitive, int minLength, int maxLength,
  642.             string[] channels, string[] selectedGenre, string startdate, string starttime, string enddate, string endtime)
  643.         {
  644.             Schedule scheduleHelper = Global.Schedule;
  645.  
  646.             ProgrammeDisplay displayProgramme = new ProgrammeDisplay();
  647.  
  648.             // build up a list of the recording we already know about
  649.             IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  650.  
  651.             if (sr_searchResults.SelectedValue != "tree")
  652.             {
  653.                 createHeaderRow();
  654.             }
  655.  
  656.             if (searchFor != null)
  657.             {
  658.                 if (!caseSensitive)
  659.                 {
  660.                     searchFor = searchFor.ToUpper();
  661.                 }
  662.             }
  663.  
  664.             //Instantiate a new search engine
  665.             SearchEngine search = new SearchEngine();
  666.  
  667.             //Set the date variables for search processing
  668.             search.setSearchDateTime(startdate, starttime, enddate, endtime);
  669.  
  670.             //Call the method that will load an array with programmes that match the passed in search criteria
  671.             ArrayList ProgrammeArray = new ArrayList(search.SelectProgrammes(channels, selectedGenre, checkTitle, checkDesc, checkSubtitle, matchTitle, matchDesc, matchSubtitle, matchUniqueID, searchFor, caseSensitive, scheduleHelper, minLength, maxLength));
  672.  
  673.             //Release resources held by the search engine object
  674.             search.Dispose();
  675.  
  676.             if (sr_searchResults.SelectedValue == "tree")
  677.             {
  678.                 foreach (Programme program in ProgrammeArray)
  679.                 {
  680.                     ScheduledRecording scheduledRecording = null;
  681.                     if (knownRecordings.Contains(program.getOID()))
  682.                         scheduledRecording = (ScheduledRecording)knownRecordings[program.getOID()];
  683.                     createOutputTable(program, scheduleHelper.GetChannelByOID(program.getChannelOID()),
  684.                                       scheduledRecording, displayProgramme);
  685.                 }
  686.                 //Resize the array of ProgrammeTreeItems so that is isn't hogging up space.
  687.                 Array.Resize(ref pgmTree, treeIdx);
  688.                 TreeView1.Nodes.Clear();
  689.                 //Fill the TreView Control with all the nodes in the correct format
  690.                 displayProgramme.FillProgrammeTree(TreeView1, pgmTree, srtOrder.SelectedValue);
  691.             }
  692.             else
  693.             {
  694.                 CSSProgrammeTableLoad tableLoad = new CSSProgrammeTableLoad();
  695.  
  696.                 foreach (Programme program in ProgrammeArray)
  697.                 {
  698.                     displayProgrammeSort.Add(program);
  699.                 }
  700.  
  701.                 //Clear the arraylist of programmes to free up resources since we are done with it
  702.                 ProgrammeArray.Clear();
  703.  
  704.                 //Sort the matching programmes into the choosen sort order
  705.                 tableLoad.sortDisplay(sortOrders, displayProgrammeSort, false);
  706.  
  707.                 //Load the now sorted matching results into the table
  708.                 while (displayProgrammeSort.Count > 0)
  709.                 {
  710.                     ScheduledRecording scheduledRecording = null;
  711.                     Programme pgm = (Programme) displayProgrammeSort[0];
  712.                     if (knownRecordings.Contains(pgm.getOID()))
  713.                         scheduledRecording = (ScheduledRecording) knownRecordings[pgm.getOID()];
  714.                     createOutputTable(pgm, scheduleHelper.GetChannelByOID(pgm.getChannelOID()),
  715.                                       scheduledRecording, displayProgramme);
  716.                     displayProgrammeSort.RemoveAt(0);
  717.                 }
  718.             }
  719.  
  720.             if (Recordings.Items.Count > 0)
  721.             {
  722.                 System.Web.UI.WebControls.DropDownList FailedRecordings = new System.Web.UI.WebControls.DropDownList();
  723.                 string [] programmeInfo;
  724.                 knownRecordings = scheduleHelper.LoadKnownRecordings();
  725.                 for (int i = 0; i < Recordings.Items.Count; i++)
  726.                 {
  727.                     programmeInfo = Recordings.Items[i].Value.Split('@');
  728.                     if (!knownRecordings.Contains(System.Convert.ToInt32(programmeInfo[0])))
  729.                     {
  730.                         FailedRecordings.Items.Add(programmeInfo[1]);
  731.                     }
  732.                 }
  733.                 if (FailedRecordings.Items.Count > 0)
  734.                 {
  735.                     Recordings.Items.Clear();
  736.                     System.Web.UI.WebControls.ListItem [] failures = new ListItem[FailedRecordings.Items.Count];
  737.                     FailedRecordings.Items.CopyTo(failures,0);
  738.                     Recordings.Items.AddRange(failures);
  739.                     RecordMessage.Text = "Recordings That Failed to Schedule:";
  740.                     Recordings.Visible = true;
  741.                     RecordMessage.Visible = true;
  742.                 }
  743.                 else
  744.                 {
  745.                     Recordings.Items.Clear();
  746.                     Recordings.Visible = false;
  747.                     RecordMessage.Visible = false;
  748.                 }
  749.             }
  750.  
  751.             displayProgramme.Dispose();
  752.         }
  753.  
  754.         private void createOutputTable(Programme programme, Channel channel, ScheduledRecording scheduledRecording, ProgrammeDisplay displayProgramme)
  755.         {
  756.             if (sr_searchResults.SelectedValue == "tree")
  757.             {
  758.                 #region Code used to load a ProgrammeTreeItem Object with the correct formatted show information and then stuff in an Array
  759.                 //Create a ProgrammeTreeItem to be loaded with the correct display information for the program
  760.                 ProgramTreeItem treeItem = new ProgramTreeItem();
  761.                 displayProgramme.FillProgrammeTreeArrayItem(treeItem, Server, programme, scheduledRecording, true, channel);
  762.                 //Add the loaded ProgrammeTreeITem to the Array
  763.                 pgmTree[treeIdx] = treeItem;
  764.                 treeIdx = treeIdx + 1;
  765.                 #endregion
  766.             }
  767.             else
  768.             {
  769.                 #region Code used to load the table cells of a table row displaying the formatted show information
  770.                 // Program Description
  771.                 TableCell detailColDetails = new TableCell();
  772.                 displayProgramme.FillProgrammeDisplay(Server, detailColDetails, programme, scheduledRecording, true);
  773.  
  774.                 TableRow detailRow = new TableRow();
  775.                 TableCell detailCol1 = new TableCell();
  776.                 if (scheduledRecording == null)
  777.                 {
  778.                     detailCol1.Text = "<input name=\"item" + programme.getOID().ToString() + "\" type=\"checkbox\" value=\"" + programme.getOID().ToString() + "\">";
  779.                 }
  780.                 detailCol1.CssClass = detailColDetails.CssClass;
  781.                 detailRow.Cells.Add(detailCol1);
  782.  
  783.                 TableCell detailCol3 = new TableCell();
  784.                 detailCol3.Text = channel.getName();
  785.                 detailCol3.CssClass = detailColDetails.CssClass;
  786.                 detailRow.Cells.Add(detailCol3);
  787.  
  788.                 detailRow.Cells.Add(detailColDetails);
  789.  
  790.                 TableCell detailCol4 = new TableCell();
  791.                 detailCol4.Text = programme.getStartTime().ToLongDateString() + "<br><nobr>" + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString() + "</nobr>";
  792.                 detailCol4.CssClass = detailColDetails.CssClass;
  793.                 detailRow.Cells.Add(detailCol4);
  794.  
  795.                 tableResults.Rows.Add(detailRow);
  796.                 #endregion
  797.             }
  798.         }
  799.  
  800.         private void createHeaderRow() {
  801.             TableRow headerRow = new TableRow();
  802.  
  803.             TableCell col1 = new TableCell();
  804.             col1.CssClass = "header";
  805.             col1.Text = "<nobr><input type=\"checkbox\" class=\"selectall\" onclick=\"SelectAllCheckboxes(this);\"><b>Select</b></nobr>";
  806.             headerRow.Cells.Add(col1);
  807.  
  808.             TableCell col3 = new TableCell();
  809.             col3.CssClass = "header";
  810.             col3.Text = "<a href=\"SearchResults.aspx?sort=channel\">Channel</a>" + getSortDescription(sortOrders[0], "channel");
  811.             headerRow.Cells.Add(col3);
  812.  
  813.             TableCell col3a = new TableCell();
  814.             col3a.CssClass = "header";
  815.             col3a.Text = "<a href=\"SearchResults.aspx?sort=title\">Show</a>" + getSortDescription(sortOrders[0], "title");
  816.             headerRow.Cells.Add(col3a);
  817.  
  818.             TableCell col4 = new TableCell();
  819.             col4.CssClass = "header";
  820.             col4.Text = "<a href=\"SearchResults.aspx?sort=datetime\">Air Date</a>" + getSortDescription(sortOrders[0], "datetime");
  821.             headerRow.Cells.Add(col4);
  822.  
  823.             tableResults.Rows.Add(headerRow);
  824.  
  825.         }
  826.  
  827.         static string getSortDescription(object selectedSort, string thisSort)
  828.         {
  829.             if (selectedSort.ToString() == thisSort)
  830.                 return " (asc)";
  831.             else if (selectedSort.ToString() == thisSort + " desc")
  832.                 return " (desc)";
  833.             else
  834.                 return string.Empty;
  835.         }
  836.  
  837.         #region Web Form Designer generated code
  838.         override protected void OnInit(EventArgs e)
  839.         {
  840.             //
  841.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  842.             //
  843.             InitializeComponent();
  844.             base.OnInit(e);
  845.         }
  846.  
  847.         /// <summary>
  848.         /// Required method for Designer support - do not modify
  849.         /// the contents of this method with the code editor.
  850.         /// </summary>
  851.         private void InitializeComponent()
  852.         {
  853.             this.PreRender += new System.EventHandler(this.SearchResults_PreRender);
  854.         }
  855.         #endregion
  856.  
  857. }
  858. }
  859.  
  860.